package com.cungmua.app.activity;

import android.os.Bundle;

import com.cungmua.app.handler.ListDealHandler;
import com.cungmua.app.handler.NewDealHandler;
import com.cungmua.app.model.User;
import com.cungmua.app.model.request.ListDealRequest;
import com.cungmua.app.model.request.LoginRequest;
import com.cungmua.app.model.request.NewDealRequest;
import com.cungmua.app.model.response.ListDealResponse;
import com.cungmua.app.model.response.NewDealResponse;
import com.cungmua.app.task.HotDealTask;
import com.cungmua.app.task.NewDealTask;

/**
 * Created by kelvin.nguyen on 6/16/14.
 */
public class ListDealActivity extends DealListActivity  implements ListDealHandler, NewDealHandler {
    public static final int NEWEST = 1;
    public static final int HOTEST = 0;
    public static final String DEALTYPE = "dealType";
    private int dealType;
    private long lastPressedTime;
    private static final int PERIOD = 2000;



    @Override
    public void loadControls(Bundle savedInstanceState) {
        dealType = HOTEST;
        super.loadControls(savedInstanceState);
        if (getIntent().getExtras() != null) {
            dealType = getIntent().getExtras().getInt(DEALTYPE);
        }


    }

    @Override
    public void updateView() {
        if (dealType == HOTEST) {
            setBackgroudImageButton(true);
            ListDealRequest request = new ListDealRequest(getDeviceId(), getToken());
            request.setCityId(getCurrentCity().getId());
            request.setUserId(getCurrentUser().getId());
            request.setPageIndex(currentPage);
            HotDealTask task = new HotDealTask(this, this);
            task.execute(request);
//            setEmptyView("Không có khuyến mãi nào hot");
        } else if (dealType == NEWEST) {
            setBackgroudImageButton(false);
            NewDealRequest request = new NewDealRequest(getDeviceId(), getToken());
            request.setCityId(getCurrentCity().getId());
            request.setUserId(getCurrentUser().getId());
            request.setPageIndex(currentPage);
            NewDealTask task = new NewDealTask(this, this);
            task.execute(request);
//          setEm  setEmptyView("Không có khuyến mãi nào mới nhất");
        }
    }

    @Override
    public void setDealType(int dealType) {
        this.dealType = dealType;
    }



    @Override
    public void onListDealReceived(ListDealResponse response) {
        onListDealData(response);
    }

    @Override
    public void onListNewDeal(NewDealResponse response) {
        onListDealData(response);
    }

    @Override
    public void setLastLoginRequest(LoginRequest request) {

    }

    @Override
    public void setCurrentUser(User data) {

    }
}
